package org.jeecg.modules.business.third.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.business.third.entity.EmsOrDmsDeliveryDto;
import org.jeecg.modules.business.third.service.IEmsOrDmsDeliveryOperateService;
import org.jeecg.modules.business.third.service.IThirdCommonService;
import org.jeecg.modules.business.third.strategy.emsdms.ThirdOperateStrategyContext;
import org.springframework.stereotype.Service;

import java.util.Map;

/*
 * 项目名称:    wms-server-jeecg
 * 接口描述:    //
 * 创建人员:    zhaojun
 * 创建时间:    2023-10-06
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class EmsOrDmsDeliveryOperateServiceImpl implements IEmsOrDmsDeliveryOperateService {

    private final IThirdCommonService thirdCommonService;
    private final ThirdOperateStrategyContext thirdOperateStrategyContext;

    @Override
    public boolean warehouse(EmsOrDmsDeliveryDto emsOrDmsDeliveryDto) {
        Integer taskOrReciptType = null;
        if (StringUtils.isNotBlank(emsOrDmsDeliveryDto.getReceiptId())) {
            taskOrReciptType = 1;
        } else {
            taskOrReciptType = 2;
        }
        Map<String, Object> map = thirdCommonService.warehouseReceiptMaterialVoes(emsOrDmsDeliveryDto.getTaskId(), emsOrDmsDeliveryDto.getReceiptId(), taskOrReciptType);

        if (ObjectUtils.isNotEmpty(emsOrDmsDeliveryDto.getType())) {
            map.put("type", emsOrDmsDeliveryDto.getType());
        }
        return thirdOperateStrategyContext.action(map.get("documentType").toString(), map);
    }

    @Override
    public boolean outbound(EmsOrDmsDeliveryDto emsOrDmsDeliveryDto) {
        Integer taskOrReciptType = null;
        if (StringUtils.isNotBlank(emsOrDmsDeliveryDto.getReceiptId())) {
            taskOrReciptType = 1;
        } else {
            taskOrReciptType = 2;
        }
        Map<String, Object> map = thirdCommonService.outboundReceiptMaterialVoes(emsOrDmsDeliveryDto.getTaskId(), emsOrDmsDeliveryDto.getReceiptId(), taskOrReciptType);
        if (ObjectUtils.isNotEmpty(emsOrDmsDeliveryDto.getType())) {
            map.put("type", emsOrDmsDeliveryDto.getType());
        }

        return thirdOperateStrategyContext.action(map.get("documentType").toString(), map);
    }

    @Override
    public boolean move(EmsOrDmsDeliveryDto emsOrDmsDeliveryDto) {

        Map<String, Object> map = thirdCommonService.moveMaterialVoes(emsOrDmsDeliveryDto.getReceiptId());
        if (ObjectUtils.isNotEmpty(emsOrDmsDeliveryDto.getType())) {
            map.put("type", emsOrDmsDeliveryDto.getType());
        }

        return thirdOperateStrategyContext.action(map.get("documentType").toString(), map);
    }
}
